﻿using HCQ2_Common;
using HCQ2_IBLL;
using HCQ2_Model;
using HCQ2_Model.APIBase;
using HCQ2_Model.VRDD.InputDto._20220314;
using HCQ2_Model.VRDD.InputDto._211217;
using HCQ2_Model.VRDD.OutputDto._20220314;
using HCQ2_Model.VRDD.OutputDto._211217;
using HCQ2_Model.VRQDMeta.InputDto._20220112;
using HCQ2_Model.VRQDMeta.OutputDto._20220112;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace HCQ2_BLL
{
    public partial class T_VRDDEventBLL: IT_VRDDEventBLL
    {
        /// <summary>
        ///  按日期删除事件提醒
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public int DeleteMemoRemindByDate(InputDeleteMemoAlert param)
        {
            return DBSession.IT_VRDDEventDAL.DeleteMemoRemindByDate(param);
        }
        /// <summary>
        ///  获取事件列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputMemoList> GetMemoList(InputMemoList param)
        {
            var list = DBSession.IT_VRDDEventDAL.GetMemoList(param);
            list?.ForEach(s =>
            {
                if (!string.IsNullOrEmpty(s.Image))
                    s.Image = s.Image.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                if (!string.IsNullOrEmpty(s.Audio))
                    s.Audio = s.Audio.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                if (!string.IsNullOrEmpty(s.Video))
                    s.Video = s.Video.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            return list;
        }
        /// <summary>
        ///  获取事件提醒列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputMemoRemindList> GetMemoRemindList(InputMemoRemindList param)
        {
            //BasePage<OutputMemoRemindList> result = new BasePage<OutputMemoRemindList>();
            int total;
            var list = DBSession.IT_VRDDEventDAL.GetMemoRemindList(param,out total);
            if (total <= 0)
                return list;
            //result.total = total;
            list?.ForEach(s =>
            {
                if (!string.IsNullOrEmpty(s.Image))
                    s.Image = s.Image.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                if (!string.IsNullOrEmpty(s.Audio))
                    s.Audio = s.Audio.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                if (!string.IsNullOrEmpty(s.Video))
                    s.Video = s.Video.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            //result.rows = list;
            return list;
        }
        /// <summary>
        ///  获取事件提醒日期列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputMemoDateList> GetMemoDateList(InputMemoDateList param)
        {
            return DBSession.IT_VRDDEventDAL.GetMemoDateList(param);
        }
        /// <summary>
        ///  获取应用商品列表
        /// </summary>
        /// <returns></returns>
        public List<OutputMetaResult> GetMetaResult(InputMetaAppList param, int user_id, int create_id)
        {
            var list = DBSession.IT_VRDDEventDAL.GetMetaResult(param, user_id,create_id);
            list?.ForEach(o =>
            {             
                //1、缩略图列表
                List<T_DocBagFileRecord> fileImage = DBSession.IT_DocBagFileRecordDAL.Select(s => s.file_id == o.fileID);
                if (fileImage.Count > 0)
                    fileImage.ForEach(s => s.file_url = s.file_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))));
                o.fileImage = fileImage;
                //2、价格列表
                List<MetaAppListPrice> listPrice = new List<MetaAppListPrice>();
                List<T_VRGoodDisiPrice> price = DBSession.IT_VRGoodDisiPriceDAL.Select(s => s.file_id == o.fileID);
                price?.ForEach(n => listPrice.Add(new MetaAppListPrice
                {
                    name = n.price_name,
                    month = n.op_month,
                    price = n.ori_price
                }));
                o.listPrice = listPrice;
                //3、最大时长
                o.timeSpan = Math.Round((decimal)o.finish_time / 60 / 60, 2);
            });
            return list;
        }
        /// <summary>
        ///  获取房间商品列表
        /// </summary>
        /// <returns></returns>
        public List<OutputMetaRoomResult> GetMetaRoomResult(InputMetaRoomList param, int user_id,int create_id)
        {
            var list = DBSession.IT_VRDDEventDAL.GetMetaRoomResult(param, user_id,create_id);
            List<OutputMetaRoomResult> result = new List<OutputMetaRoomResult>();
            list?.ForEach(o =>
            {
                //1、创建人头像
                if (!string.IsNullOrEmpty(o.createImage))
                    o.createImage = o.createImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                //使用应用
                o.attachUrl = o.attach_url;
                //2、缩略图列表
                if (string.IsNullOrEmpty(o.imageUrl))
                    o.imageUrl = o.image_url;
                var obj = Helper.AutoMapperConvert<OutputMetaRoomResult, OutputMetaRoom>(o);
                result.Add(obj);
            });
            return result;
        }

        /// <summary>
        ///  获取素材商品列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public BasePage<MaterialListOutput> GetMaterialList(MaterialListInput param,int user_id,int create_id)
        {
            BasePage<MaterialListOutput> result = new BasePage<MaterialListOutput>();
            int total;
            List<MaterialListOutput> list = DBSession.IT_VRDDEventDAL.GetMaterialList(param, user_id,create_id, out total);
            if (list == null || list.Count <= 0)
                return result;
            result.total = total;
            list?.ForEach(s => {
                //1、缩略图
                List<BagFileImage> fileImage = new List<BagFileImage>();
                List<T_DocBagFileRecord> bag = DBSession.IT_DocBagFileRecordDAL.Select(n => n.file_id == s.fileID);
                bag?.ForEach(o => fileImage.Add(new BagFileImage { bag_id = o.bag_id, file_url = o.file_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))) }));
                s.fileImage = fileImage;
                //2、价格列表
                List<PriceListResult> listPrice = new List<PriceListResult>();
                List<T_VRGoodDisiPrice> pirce = DBSession.IT_VRGoodDisiPriceDAL.Select(n => n.file_id == s.fileID);
                pirce?.ForEach(o => listPrice.Add(new PriceListResult { month = o.op_month, name = o.price_name, price = o.ori_price }));
                s.listPrice = listPrice;
                //3、创建人头像
                if (!string.IsNullOrEmpty(s.createImage))
                    s.createImage = s.createImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            result.rows = list;
            return result;
        }
        /// <summary>
        ///  获取用户已购买的素材列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public BasePage<PaidMaterialOutput> GetPaidMaterialList(PayPaidMaterialInput param, int user_id)
        {
            BasePage<PaidMaterialOutput> result = new BasePage<PaidMaterialOutput>();
            int total;
            List<PaidMaterialOutput> list = DBSession.IT_VRDDEventDAL.GetPaidMaterialList(param, user_id, out total);
            if (list == null || list.Count <= 0)
                return result;
            result.total = total;
            list?.ForEach(s => {
                //1、缩略图
                List<BagFileImage> fileImage = new List<BagFileImage>();
                List<T_DocBagFileRecord> bag = DBSession.IT_DocBagFileRecordDAL.Select(n => n.file_id == s.fileID);
                bag?.ForEach(o => fileImage.Add(new BagFileImage { bag_id = o.bag_id, file_url = o.file_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))) }));
                s.fileImage = fileImage;
                //2、价格列表
                List<PriceMoney> listPrice = new List<PriceMoney>();
                List<T_VRGoodDisiPrice> pirce = DBSession.IT_VRGoodDisiPriceDAL.Select(n => n.file_id == s.fileID);
                pirce?.ForEach(o => listPrice.Add(new PriceMoney { month = o.op_month, price = o.ori_price }));
                s.listPrice = listPrice;
                //3、创建人头像
                if (!string.IsNullOrEmpty(s.createImage))
                    s.createImage = s.createImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            result.rows = list;
            return result;
        }
    }
}